﻿using Entity.BaseSplit;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Utility.Helper;

namespace Entity.BaseEntitys
{


    
    public interface IEntity<TKey>
    {
        /// <summary>
        ///A primary key
        /// </summary>

        TKey Id { get; set;}

        /// <summary>
        /// Depots field
        /// </summary>
        string SplitArea { get; set; }

        /// <summary>
        /// To prevent concurrent pessimistic locking
        /// </summary>
        [Timestamp]
        [Column(TypeName = "timestamp")]//Deals with the problem of compatible type
        byte[] TimeStamp { get; set; }
    }


    [Index(nameof(SplitArea))]
    public class Entity<TKey> : IEntity<TKey>
    {

        [Key]
        public virtual TKey Id { get; set; }

        [Required]
        public string SplitArea { get; set; } = SplitAreaSource.GetAreaSource();

        [Timestamp]
        [Column(TypeName = "timestamp")]
        public byte[] TimeStamp { get; set; }
    }

}
